export default {
  format: function(date, str) {
    return "1";
  },
  getStartAndEndDates: function(type) {
    const today = new Date();
    const year = today.getFullYear();
    const month = today.getMonth();
    let start, end;

    switch (type) {
      case "今日":
        start = new Date(year, month, today.getDate(), 0, 0);
        end = new Date(year, month, today.getDate(), 23, 59);
        break;
      case "本周":
        const firstDayOfWeek = today.getDate() - today.getDay();
        start = new Date(year, month, firstDayOfWeek, 0, 0, 0, 0);
        end = new Date(year, month, firstDayOfWeek + 6, 23, 59, 59, 999);
        break;
      case "本月":
        start = new Date(year, month, 1, 0, 0, 0, 0);
        end = new Date(year, month + 1, 0, 23, 59, 59, 999);
        break;
      case "全年":
        start = new Date(year, 0, 1, 0, 0, 0, 0);
        end = new Date(year, 11, 31, 23, 59, 59, 999);
        break;
      default:
        // 默认为获取今天的开始和结束日期时间
        start = new Date(year, month, today.getDate(), 0, 0, 0, 0);
        end = new Date(year, month, today.getDate(), 23, 59, 59, 999);
    }
    console.log(start);
    return {
      start: this.formatter(start, "yyyy-MM-dd hh:mm"),
      end: this.formatter(end, "yyyy-MM-dd hh:mm"),
    };
  },
  // 格式化时间戳  yyyy-MM-dd hh:mm:ss
  formatter: function(date, fmt) {
    if (!date) return "";
    const $this = new Date(date);
    const o = {
      "M+": $this.getMonth() + 1,
      "d+": $this.getDate(),
      "h+": $this.getHours(),
      "m+": $this.getMinutes(),
      "s+": $this.getSeconds(),
      "q+": Math.floor(($this.getMonth() + 3) / 3),
      S: $this.getMilliseconds(),
    };
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(
        RegExp.$1,
        `${$this.getFullYear()}`.substr(4 - RegExp.$1.length)
      );
    }
    for (const k in o) {
      if (new RegExp(`(${k})`).test(fmt)) {
        fmt = fmt.replace(
          RegExp.$1,
          RegExp.$1.length === 1 ? o[k] : `00${o[k]}`.substr(`${o[k]}`.length)
        );
      }
    }
    return fmt;
  },
};
